package org.example.hrpc.rpc.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.example.hrpc.common.spi.loader.ExtensionLoader;
import org.example.hrpc.rpc.core.InvocationRunnable;
import org.example.hrpc.rpc.core.Protocol;
import org.example.hrpc.rpc.message.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TransportServerHandler extends SimpleChannelInboundHandler<Request> {
    private static final Logger logger = LoggerFactory.getLogger(TransportServerHandler.class);
    private ExecutorService executor;


    public TransportServerHandler() {
        this.executor = Executors.newFixedThreadPool(10);
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Request request) throws Exception {
        logger.info("Server receive request message: {}", request);
        executor.execute(new InvocationRunnable(channelHandlerContext.channel(), request));
    }
}
